package com.genius.workflow.log;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

@Configuration
@ConfigurationProperties(prefix="threadlogpool")
public class ExecuteGeniusLogPoolConfiguration {
	private static Logger logger = LoggerFactory.getLogger(ExecuteGeniusLogPoolConfiguration.class);
	
	@Value("${threadlogpool.corePoolSize}")
    private int corePoolSize;
	
	@Value("${threadlogpool.maxPoolSize}")
    private int maxPoolSize;
	
	@Value("${threadlogpool.queueCapacity}")
    private int queueCapacity;
	
	@Value("${threadlogpool.keepAliveSeconds}")
    private int keepAliveSeconds;

	@Bean(name="threadPoolTaskExecutor")
	public ThreadPoolTaskExecutor threadPoolTaskExecutor(){
		ThreadPoolTaskExecutor pool = new ThreadPoolTaskExecutor();
		pool.setCorePoolSize(corePoolSize);//核心线程池数
		pool.setMaxPoolSize(maxPoolSize); // 最大线程
		pool.setQueueCapacity(queueCapacity);//队列容量
		pool.setKeepAliveSeconds(keepAliveSeconds);
		pool.setRejectedExecutionHandler(new java.util.concurrent.ThreadPoolExecutor.CallerRunsPolicy()); //队列满，线程被拒绝执行策略
		return pool;
	}
}
